﻿using System;
using System.Text;
using VoteServices;
using VoteServices.VoteModel;

namespace Vote
{
    class Program
    {

        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            ProblemService problemService = new ProblemService();
            RecordService recordService = new RecordService();
            UserService userService = new UserService();
            User user = new User();
            user = userService.Login();
            if (user == null)
            {
                Console.WriteLine("你的三次机会全部用完，请重新打开系统！");
            }
            else
            {
                int a = Println();
                NewMethod(a, recordService, user, problemService);
                Boolean T = true;
                string ch;
                while (T)
                {
                    Console.WriteLine("是否想继续操作？(Y/N)");
                    ch = Console.ReadLine();
                    if (ch.Equals("Y"))
                    {
                        Console.WriteLine("请按照序号选择你想进行的功能！");
                        int answer = Convert.ToInt32(Console.ReadLine());
                        NewMethod(answer, recordService, user, problemService);
                    }
                    else
                        T = false;

                }

            }

        }
        public static int Println()
        {

            Console.WriteLine("*****************************************");
            Console.WriteLine("*******请按照相应功能选择你的操作********");
            Console.WriteLine("1、参与投票");
            Console.WriteLine("2、查看投票统计");
            Console.WriteLine("3、问题过期检测");
            Console.WriteLine("4、退出");

            int index = Convert.ToInt32(Console.ReadLine());
            return index;
        }
        public static void NewMethod(int a, RecordService service, User user, ProblemService problemService)
        {
            switch (a)
            {
                case 1:
                    service.Voting(user);
                    break;
                case 2:
                    service.Statics();
                    break;
                case 3:
                    problemService.CheckTime();
                    break;
                case 4:
                    Console.WriteLine("下次见！！");
                    System.Environment.Exit(0);
                    break;
                default:
                    System.Environment.Exit(0);
                    break;
            }
        }


    }
}


